{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "6c070366",
   "metadata": {},
   "source": [
    "# python基础入门3_选择语句&循环语句"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e3e411f1",
   "metadata": {},
   "source": [
    "## 双分支条件语句"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "a1dfeffc",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入一个自然数：1\n",
      "1 is odd number.\n"
     ]
    }
   ],
   "source": [
    "#判断自然数的奇偶性\n",
    "num = input(\"请输入一个自然数：\")\n",
    "\n",
    "num = int(num)#string-->int\n",
    "\n",
    "if num%2==0:\n",
    "    print(\"{num} is even number.\".format(num=num))\n",
    "else:\n",
    "    print(\"{num} is odd number.\".format(num=num))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "008fe499",
   "metadata": {},
   "outputs": [],
   "source": [
    "#分支语句后面不要忘记写冒号！！！"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "77e4f774",
   "metadata": {},
   "source": [
    "## 多分支条件语句"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "3237892c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "优\n"
     ]
    }
   ],
   "source": [
    "grade = \"A\"\n",
    "\n",
    "if grade==\"A\":\n",
    "    print(\"优\")\n",
    "elif grade==\"B\":\n",
    "    print(\"良\")\n",
    "else:\n",
    "    print(\"差\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "edf2e55a",
   "metadata": {},
   "source": [
    "## for循环"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "d30397fd",
   "metadata": {},
   "outputs": [],
   "source": [
    "lst = range(0,10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2e444dee",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
